﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KAKA.Repository;
using Morus;

namespace KAKA.Domain
{
    public static class UserExtension
    {
        public static bool IsUnique(this User user)
        {
            return IoC.Resolve<IUserRepository>().Get(user.Username) == null;
        }

        public static bool IsAdministrator(this User user)
        {
            return user != null && user.Role == Role.Administrator;
        }

        public static bool CanSendTextMessage(this User user)
        {
            var oneHourSentMessages = user.Proofs.Where(r => r.CreateAt.Date == DateTime.Today && r.CreateAt.Hour == DateTime.Today.Hour).ToList();
            var allowedTextMessageCount = IoC.Resolve<SettingRepository>().GetByName(Setting.NAME_ONE_HOUR_ALLOWED_TEXT_MESSAGE_COUNT);
            return oneHourSentMessages.Count < int.Parse(allowedTextMessageCount.Value);
        }
    }
}
